package com.example.yuejian21.nongfusanquan.yuejian21.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.example.yuejian21.nongfusanquan.yuejian21.R;
import com.example.yuejian21.nongfusanquan.yuejian21.adapter.OrderAdapter;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.Orderbean;
import com.example.yuejian21.nongfusanquan.yuejian21.model.Usermodel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class OrderlistActivity extends Activity {
    //声明
    private ImageView left;
    private int u_id;
    private RecyclerView recyclerView;
    private Button activityOrder_button,matchOrder_button,trainOrder_button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_train_order_list);
        initViews();//初始化
        initEvent();
        initData();//点击事件处理
    }

    private void initViews() {
        recyclerView = (RecyclerView) findViewById(R.id.my_order);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));//设置布局

        left = (ImageView) findViewById(R.id.left);
    }
    private void initEvent() {
        //返回上一页
        left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });





    }

    private void initData() {
        SharedPreferences sp =this.getSharedPreferences("cache", Context.MODE_APPEND);
        u_id = Integer.parseInt(sp.getString("uid","0"));
//             Log.d("we","u_id");

        Usermodel userModel = new Usermodel();
        //发送请求
        Call<List<Orderbean>> call = userModel.getMyTrainOrderlist
                (u_id);
        //2.处理结果
        call.enqueue(new Callback<List<Orderbean>>() {
            @Override
            public void onResponse(Call<List<Orderbean>> call, Response<List<Orderbean>> response) {
                List<Orderbean> data = (List<Orderbean>) response.body();  //获取数据
                recyclerView.setAdapter(new OrderAdapter(OrderlistActivity.this, data));
            }

            @Override
            public void onFailure(Call<List<Orderbean>> call, Throwable t) {

            }

        });

    }
}

